package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import domain.User;
import service.UserService;
import service.impl.UserServiceImpl;
import utils.StringUtil;


/**
 * AddInfo实现类
 */
@WebServlet("/AddInfoServlet")
public class AddInfoServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private final UserDao userDao = new UserDaoImpl();
    private final UserService userService = new UserServiceImpl();

    public AddInfoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //request.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession();
        User user = ((User) session.getAttribute("user"));

        String realName = request.getParameter("realname");
        String phone = request.getParameter("phone");
        String birth = request.getParameter("birth");

        user.setRealname(realName);
        user.setPhone(phone);
        user.setBirth(birth);
        //request.getAttribute("user");
        userService.addInfo(user);

        request.setAttribute("AddInfoResult", "补充信息成功！");
        request.getRequestDispatcher("/AddInfo.jsp").forward(request, response);
        return;
    }

}